<template>
  <div>
    <!-- <button @click="$router.push('/order')">地址</button> -->
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect"
    ></van-address-list>
  </div>
</template>

<script>
import { Toast } from "vant";
import { reqAddressList } from "../../http/api";
export default {
  mounted() {
    let arr = [];
    reqAddressList({
      uid: JSON.parse(localStorage.getItem("user")).uid,
    }).then((res) => {
      arr = res.data.list ? res.data.list : [''];
      if (res.data.code == 200) {
        //   console.log(res);
        this.list = res.data.list.map((item) => {
          return {
            id: item.id,
            name: item.username,
            tel: item.userphone,
            address: item.location + item.useraddress,
            isDefault: item.status === 1,
          };
        });
      }
    });
  },
  data() {
    return {
      chosenAddressId: "1",
      list: [
        // {
        //   id: "1",
        //   name: "张三",
        //   tel: "13000000000",
        //   address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
        //   isDefault: true,
        // },
        // {
        //   id: "2",
        //   name: "李四",
        //   tel: "1310000000",
        //   address: "浙江省杭州市拱墅区莫干山路 50 号",
        //   isDefault: true,
        // },
      ],
    };
  },
  methods: {
    onAdd() {
    //   Toast("新增地址");
      this.$router.push("/newAddress");
    },
    onEdit(item, index) {
    //   Toast("编辑地址:" + index);
      this.$router.push("/newAddress?id="+item.id);
    },
    onSelect(item,index){
        this.$router.push('/order?addressId='+item.id)
    }
  },
};
</script>

<style scoped>
.van-address-item {
  display: flex;
}
.lists {
  overflow: hidden;
}
.van-radio {
  float: left;
  font-size: 0.3rem;
}
.addAddress {
  width: 80%;
  height: 0.8rem;
  line-height: 0.8rem;
  text-align: center;
  /* margin: 0 auto; */
  background: tomato;
  border-radius: 0.4rem;
  position: fixed;
  left: 10%;
  bottom: 0.1rem;
  font-size: 0.4rem;
  color: white;
}
</style>